<?php

namespace App\Containers\AppSection\Questionnaire\Models;

use App\Ship\Parents\Models\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Поле
 *
 * @property int $id Id
 * @property int $field_id Поле
 * @property int $response_id Ответ
 * @property string $person Лицо
 * @property array $value Значение
 *
 * @property Field $field Поле
 * @property Response $response Ответ
 */
class Value extends Model
{
    public $timestamps = false;
    protected $fillable = [
        'field_id',
        'response_id',
        'person',
        'value',
    ];
    protected $dates = [
        'created_at',
        'updated_at',
    ];
    /**
     * A resource key to be used in the serialized responses.
     */
    protected string $resourceKey = 'Value';
    protected $table = 'questionnaire_values';
    protected $casts = [
        'value' => 'json',
    ];

    /**
     * Поле
     * @return BelongsTo Field
     */
    public function field(): BelongsTo
    {
        return $this->belongsTo(Field::class, 'field_id', 'id');
    }

    /**
     * Ответ
     * @return BelongsTo Response
     */
    public function response(): BelongsTo
    {
        return $this->belongsTo(Response::class, 'response_id', 'id');
    }
}
